package com.example.machine.config;

import com.example.machine.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Home-pc
 * Date: 2024-02-22
 * Time: 10:54
 */
@Slf4j
@ControllerAdvice
@ResponseBody
public class ErrorHandler {

    @ExceptionHandler
    public Result excption(Exception e){
     log.error("发生异常，e",e);
     return Result.fail("内部错误");
    }

    @ExceptionHandler
    public Result excption(NullPointerException e){
        log.error("发生异常，e",e);
        return Result.fail("NullPointerException异常");
    }

    @ExceptionHandler
    public Result excption(ArithmeticException e){
        log.error("发生异常，e",e);
        return Result.fail("ArithmeticException异常");
    }
}
